package com.wsd.smartcarwasher.controller;
import com.wsd.smartcarwasher.constans.ResultState;
import com.wsd.smartcarwasher.dao.OfflineRecordMapper;
import com.wsd.smartcarwasher.domain.MessageRecord;
import com.wsd.smartcarwasher.domain.Pagination;
import com.wsd.smartcarwasher.service.RecordService;
import com.wsd.smartcarwasher.util.ReturnUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Api(tags = {"新增==>线下订单记录表"})
@Controller
@CrossOrigin
public class OfflineRecordController {
    @Resource
    private OfflineRecordMapper offlineRecordMapper;

    @Resource
    private RecordService recordService;

    @ApiOperation(
            value = "线下洗车订单记录查询",
            notes = "线下洗车事件记录查询",
            produces = "application/json",
            response = ModelMap.class
    )
    @ApiImplicitParams({@ApiImplicitParam(
            name = "machineId",
            value = "机器id",
            required = false,
            dataType = "String"
    ), @ApiImplicitParam(
            name = "level",
            value = "消息级别",
            required = false,
            dataType = "String"
    ), @ApiImplicitParam(
            name = "eventCode",
            value = "事件码",
            required = false,
            dataType = "String"
    ), @ApiImplicitParam(
            name = "startTime",
            value = "开始事件",
            required = false,
            dataType = "Date"
    ), @ApiImplicitParam(
            name = "endTime",
            value = "结束时间",
            required = false,
            dataType = "Date"
    ), @ApiImplicitParam(
            name = "status",
            value = "处理状态",
            required = false,
            dataType = "Integer"
    )})
    @RequestMapping(
            value = {"/v1/offline/record"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    public ModelMap queryMessageRecord(@RequestParam(value = "machineId", required = false) String machineId, @RequestParam(value = "level", required = false) String level, @RequestParam(value = "eventCode", required = false) String eventCode, @RequestParam(value = "startTime", required = false) Date startTime, @RequestParam(value = "endTime", required = false) Date endTime, @RequestParam(value = "status", required = false) Integer status,
                                       @RequestParam(required = false) int Page,
                                       @RequestParam(required = false) int PageSize
    ) {
        List<MessageRecord> records = this.recordService.querylOfflineMessageRecords(machineId, level, eventCode, startTime, endTime, status,Page,PageSize);
        return ReturnUtil.Success(ResultState.QUERY_MESSAGE_RECORD_SUCCESS.getMsg(), new Pagination<MessageRecord>(Page,PageSize,records));
    }

}
